package com.exmaple.lemlin.ui.fragment;

import android.content.Intent;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.design.widget.TextInputEditText;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.exmaple.lemlin.R;
import com.exmaple.lemlin.entity.AccessEvenBus;
import com.exmaple.lemlin.ui.abstracts.AbstractBaseFragment;
import com.exmaple.lemlin.utils.JsonUtils;
import com.exmaple.lemlin.utils.LogUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author Administrator
 */
public class AccessSignInFragment extends AbstractBaseFragment {

    @BindView(R.id.edit_user_name)
    TextInputEditText editUserName;
    @BindView(R.id.edit_password)
    TextInputEditText editPassword;

    public static AccessSignInFragment newInstance() {
        return new AccessSignInFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_access_sign_in;
    }

    @Override
    protected void initView() {
    }

    @Override
    protected void initPresenter() {

    }

    @Override
    protected void initLazyLoad() {

    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    @OnClick({R.id.btn_user_login, R.id.btn_user_logon})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_user_login:
                AccessEvenBus.Authenticate auth = new AccessEvenBus.Authenticate();
                auth.setUserName(Objects.requireNonNull(editUserName.getText()).toString());
                auth.setUserPwd(Objects.requireNonNull(editPassword.getText()).toString());
                EventBus.getDefault().post(new AccessEvenBus((this), auth));
                break;
            case R.id.btn_user_logon:
                if (getActivity() == null)
                    return;
                FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                ft.add(R.id.frame_layout, AccessSignUpFragment.newInstance());
                ft.addToBackStack(null);
                ft.commit();
                break;
            default:
                break;
        }
    }
}
